package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import forms.StudentsForm;

public class AddressAction extends Action {
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		String address = request.getParameter("address");
		String city = request.getParameter("city");
		String state = request.getParameter("state");
		String zipCode = request.getParameter("zipCode");
		String areaCode = request.getParameter("areaCode");
		String countryCode = request.getParameter("countryCode");
		String phone = request.getParameter("phone");
		
		// Cast the form
		StudentsForm iForm = (StudentsForm) form;
					
		iForm.setAddress(address);
		iForm.setCity(city);
		iForm.setState(state);
		iForm.setZipCode(zipCode);
		iForm.setAreaCode(areaCode);
		iForm.setCountryCode(countryCode);
		iForm.setPhone(phone);
		
		// Permanent residency handeling
		if (iForm.getResidency().equals("United States")) {
	    	 iForm.setPermanent("true");
		     return mapping.findForward("permsuccess");
	    }
	    else
	    	return mapping.findForward("nopermsuccess");
	}
}